package Leo.serviceClient.ribbon;

import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * 配置FAQ-Service-Provider使用RibbonConfig的配置
 */
//@RibbonClient(name = "FAQ-Service-Provider",configuration = RibbonConfig.class)
//@Configuration
//@RibbonClient(name = "Second-Provider",configuration = SecondRibbonConfig.class)
public class FaqProviderConfig {
//    @Autowired
//    SpringClientFactory springClientFactory;
//    @PostConstruct
//    public void init(){
//        ILoadBalancer loadBalancer = springClientFactory.getLoadBalancer("default");
//        ILoadBalancer loadBalancer3 = springClientFactory.getLoadBalancer("Second-Provider");
//        System.out.println("default loadbalance 等于 second balance？："+loadBalancer.equals(loadBalancer3));
//        ILoadBalancer loadBalancer2 = springClientFactory.getLoadBalancer("FAQ-Service-Provider");
//        ZoneAwareLoadBalancer loadBalancer1 = (ZoneAwareLoadBalancer) loadBalancer;
//        System.out.println("default rule is :" + loadBalancer1.getRule().getClass().getName());
//        loadBalancer1.setRule(new SecondLoadbalanceRule());
//        System.out.println("new rule is :" + loadBalancer1.getRule().getClass().getName());
//        System.out.println("default ping is: " + loadBalancer1.getPing().getClass().getName());
//        loadBalancer1.setPing(new SecondPing());
//        System.out.println("new ping is: " + loadBalancer1.getPing().getClass().getName());
//    }
}
